import Qt 4.7


Rectangle {
    id: cashFlowView

    width: 525; height: 314
    color: "transparent"

    signal callEditMoney
    signal callUpdateMoneyRegisters
    signal callMessageBox(string mesgBox, string nextView)

    function initializeListView() {
        cashFlowSearch.visible = false
        chartRectangle.visible = false
        listaModeView.visible = true;

        graficoButton.turnOff();
        searchButton.turnOff();
        listaButton.isToggled = true
        listaButton.color = listaButton.toggledColor;
    }
    function updateCategories(m_model) {
        cashFlowSearch.updateCategories(m_model);
    }
    function updateMoneyRegisters(m_model) {
        listaModeView.updateMoneyRegisters(m_model);
        updateChart(m_model);
    }
    /* Create the chart dinamically whenever is needed
     *
     **/
    function updateChart(moneyList) {
        var chart_item;
        if (chart_item = chartRectangle.childAt(0,0))
            chart_item.destroy();

        var new_component = Qt.createComponent("Chart.qml");
        var new_obj = new_component.createObject(chartRectangle);

        if (new_obj == null)
            console.log("QML:CashFlowView - Error when creating chart");
        else {
            new_obj.anchors.fill = chartRectangle;
            new_obj.typeChart = 0; // 0 -> draw the Money by Time Chart
            new_obj.moneyList = moneyList;
        }
    }

    Text {
        id: addFlowLabel

        x: 38; y: 16
        text: "Caixa"; color: "#00adef"
        font { pointSize: 12; weight: Font.DemiBold; family: "Series 60 Sans" }
    }
    Button {
        id: listaButton

        x: 277; y: 0; width: 68; height: 45
        color: "#C2EBFB"
        pressedColor: "#C2EBFB"; toggledColor: "#C2EBFB"; defaultColor: "transparent"
        isToggled: true; toggleEnable: true

        onClicked: {
            graficoButton.turnOff();
            searchButton.turnOff();

            cashFlowSearch.visible = false
            chartRectangle.visible = false
            listaModeView.visible = true;

            listaButton.color = listaButton.toggledColor;

        }
        Image { source: "../resources/pixmaps/Caixa/Lista.png" }
    }
    Button {
        id: searchButton

        x: 345; y: 0; width: 68; height: 45
        color: "transparent"
        pressedColor: "#C2EBFB"; toggledColor: "#C2EBFB"; defaultColor: "transparent"
        toggleEnable: true

        onClicked: {
            cashFlowSearch.fillForm();
            graficoButton.turnOff();
            listaButton.turnOff();

            cashFlowSearch.visible = true
            chartRectangle.visible = false
            listaModeView.visible = false;

            searchButton.color = searchButton.toggledColor;
        }

        Image { source: "../resources/pixmaps/Caixa/Busca.png" }
    }
    Button {
        id: graficoButton

        x: 413; y: 0; width: 68; height: 45
        color: "transparent"
        pressedColor: "#C2EBFB"; toggledColor: "#C2EBFB"; defaultColor: "transparent"
        toggleEnable: true

        onClicked: {
            listaButton.turnOff();
            searchButton.turnOff();

            cashFlowSearch.visible = false;
            chartRectangle.visible = true;
            listaModeView.visible = false;

            graficoButton.color = graficoButton.toggledColor;
        }

        Image { source: "../resources/pixmaps/Caixa/Grafico.png" }
    }
    CashFlowList {
        id: listaModeView

        x: 0 ; y: 62;
        visible: false;
        onCallEditMoney: cashFlowView.callEditMoney();
        onCallUpdateMoneyRegisters: cashFlowView.callUpdateMoneyRegisters();
        onCallMessageBox: cashFlowView.callMessageBox(mesgBox, nextView);
    }
    CashFlowSearchView {
        id: cashFlowSearch

        x: 0; y: 62
        visible: false;

        onCallCashFlowListView: {
            graficoButton.turnOff();
            searchButton.turnOff();
            listaButton.toggle();
            cashFlowSearch.visible = false;
            cashFlowView.callUpdateMoneyRegisters();
            listaModeView.visible = true;
        }
        onCallMessageBox: {
            cashFlowView.callMessageBox(mesgBox, nextView);
        }
        onCallUpdateMoneyRegisters: {
            cashFlowView.callUpdateMoneyRegisters();
        }
    }
    Rectangle {
        id: chartRectangle

        x: 38; y: 62
        visible: false;
    }
}
